package cn.njupt.unionfind;
//最主要的是找带头人或者帮主,是一种树形结构数据结构
public abstract class Union_Find {
    protected int[] parent;

    public boolean isSameSet(int i, int j) {
        return find(i) == find(j);
    }

    public Union_Find(int capacity) {
        if (capacity <= 0) {
            throw new IllegalArgumentException("参数传递不正确");
        }
        parent = new int[capacity];
        for (int i = 0; i < parent.length; i++) {
            parent[i] = i;
        }
    }

    protected void rangCheck(int i) {
        if (i < 0 || i >= parent.length) {
            throw new IllegalArgumentException("数组角标越界");
        }
    }

    public abstract int find(int i);

    public abstract void union(int i, int j);
}
